<?php

if(isset($_POST['request_add'])){

	$params = array(
		'tid'	=> 1,//empty(trim($_POST['answer_type'])) ? 1 : trim($_POST['answer_type']),
		'title'	=> trim($_POST['answer_name']),
		'answer'=> (bool)$_POST['answer_answer'],
		'qid'	=> empty(trim($_POST['answer_qid'])) ? 1 : trim($_POST['answer_qid'])
	);
	
	if($params['title']){
		
		$params['title'] = preg_replace("/[\/\'\"]/","",$params['title']);
		$db = new models($host,$user,$pass,$db_name);
		$db->select("id");
		$db->where("title='".$params['title']."' AND qid='".$params['qid']."'");
		$answer = $db->get_data("answers");
		if(!$answer){
			$db->insert("answers",$params);
			redirect("$home_url/admin/answers/?notice=success");
		}else
			redirect("$home_url/admin/answers/?notice=duplicate");
		
	}else{
		redirect("$home_url/admin/answers/?notice=error");
	}
}